package com.zhangkunhao.notes.web.servlet;

import com.alibaba.fastjson.JSON;
import com.zhangkunhao.notes.entity.Do.Topic;
import com.zhangkunhao.notes.entity.bo.PageBean;
import com.zhangkunhao.notes.service.TopicServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 话题的controller
 *
 * @author 20642
 */
@WebServlet("/topic/*")
public class TopicServlet extends BaseDaoServlet {
    private TopicServiceImpl topicService = new TopicServiceImpl();

    /**
     * 查看没有关注的话题
     *
     * @param request:
     * @param response:
     * @throws Exception:
     */
    public void showNotPursueTopics(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 通过Session接收用户Id
        Integer id = (Integer) request.getSession().getAttribute("userId");

        //调用service层,封装返回前端的对象
        PageBean<Topic> topicPageBean = topicService.showNotPursueTopics(id);

        // 转换为json数据,写数据
        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(JSON.toJSONString(topicPageBean));
    }

    /**
     * 查看已经关注的话题
     *
     * @param request:
     * @param response:
     * @throws Exception:
     */
    public void showPursueTopics(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 通过Session接收用户Id
        Integer id = (Integer) request.getSession().getAttribute("userId");

        //调用service层,封装返回前端的对象
        PageBean<Topic> topicPageBean = topicService.showPursueTopics(id);

        // 转换为json数据,写数据
        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(JSON.toJSONString(topicPageBean));
    }
}
